package day3;

/**
 * ClassName：Teacher
 *
 * @Author：小鱼
 * @Create：2025-08-13 16:00
 */
public class Teacher implements Comparable<Teacher>{
    //属性
    private String id;
    private String name;
    private int age;

    //构造函数
    public Teacher() {
    }

    public Teacher(String id, String name, int age) {
        this.id = id;
        this.name = name;
        this.age = age;
    }

    //get。set方法
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    //重写toString方法
    @Override
    public String toString() {
        return "\nTeacher{" +
                "id='" + id + '\'' +
                ", name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public int compareTo(Teacher o) {
        int num;
        // name进行升序排序
        num=this.name.compareTo(o.name);
        if (num==0){
            //名字相同的时候通过年龄进⾏升序排序
            num = age-o.age;
        }
        if(num==0){
            //年龄相同时通过id升序排序。
            num=this.id.compareTo(o.id);
        }
        return num;
    }
}
